<template>
	<view>
			<view class="cu-card">
				<view class="cu-item padding bg-img shadow-blur bg-gradual-theme">
					<view class="flex text-white" style="align-items: center;">
						<view class="text-cut text-lg  text-bold" style="width:240rpx">可添加总人数</view>
						<!-- <text class="cuIcon-question text-white" @tap="goStock"></text> -->
						<text class="margin-left text-xxm">{{Stock.total_num || 0}} 人</text>
						
					</view>
					<view class="flex margin-top text-white" style="align-items: center;">
						<view class="text-cut text-lg text-bold" style="width:240rpx">已添加人数</view>
						<text class="margin-left text-xxm">{{Stock.available_num || 0}} 人</text>
					</view>
					<view class="flex margin-top text-white" style="align-items: center;">
						<view class="text-cut text-lg  text-bold" style="width:240rpx">剩余可添加人数</view>
						<text class="margin-left text-xxm">{{(Stock.total_num-Stock.available_num) || 0}} 人</text>
						
					</view>
					<view class="flex margin-top" style="align-items: center; justify-content: flex-end;" @tap="addPartner">
						<text class="cuIcon-roundaddfill text-white" style="font-size: 40rpx;"></text>
						<text class=" text-df" style="margin-left:10rpx;">增加合伙人</text>
					</view>
				</view>
				
			</view>
			<view class="cu-bar bg-white">
				<view class="action">
					<text class="cuIcon-titles text-theme"></text>
					<text class="text-lg text-bold">品牌合伙人列表</text>
				</view>
			</view>
			<scroll-view scroll-x class="bg-white nav">
				<view class="flex text-center">
					<!-- <view class="cu-item flex-sub":class="active===0?'text-theme cur':''" @tap="GET_PartnersList">
						已审核
					</view>
					<view class="cu-item flex-sub":class="active===1?'text-theme cur':''" @tap="GET_PartnersList">
						未审核
					</view> -->
					<view class="cu-item flex-sub":class="active===index?'text-theme cur':''" v-for="(item,index) in menuList" :key="index"  @tap="GET_PartnersList(index+1)">
						{{item.title}}
					</view>
				</view>
			</scroll-view>
			<scroll-view scroll-y="true">
				<view v-if="!PartnersList.length" class="empty">
				   <view style="margin-top: 100upx;text-align: center">
					   <view class="text-cut text-lg margin-top-sm">暂无数据</view>
				   </view>
				</view>
				<view class="cu-list menu-avatar" v-else>
					<view class="cu-item" v-for="(item,index) in PartnersList" :key="index">
						<view class="cu-avatar round lg" :style="'background-image:url('+item.face+');'"></view>
						<view class="content">
							<view class="text-cut text-df">用户名：{{item.nickname || ''}}</view>
							<view class="text-gray text-sm flex">
								<view class="text-cut">
									手机号：{{item.mobile}}
								</view>
							</view>
						</view>
						<view class="action" style="width: 200rpx;">
							<view class="text-grey text-xs">剩余{{item.available_num || '0'}}个名额</view>
						</view>
					</view>
				</view>	
			</scroll-view>
			<!-- <scroll-view scroll-y="true" v-else>
				<view v-if="!PartnersListLow.length" class="empty">
				   <view style="margin-top: 100upx;text-align: center">
					   <view class="text-cut text-lg margin-top-sm">暂无数据</view>
				   </view>
				</view>
				<view class="cu-list menu-avatar" v-else>
					<view class="cu-item" v-for="(item,index) in PartnersListLow" :key="index">
						<view class="cu-avatar round lg" :style="'background-image:url('+item.face+');'"></view>
						<view class="content">
							<view class="text-cut text-df">用户名：{{item.nickname || ''}}</view>
							<view class="text-gray text-sm flex">
								<view class="text-cut">手机号：{{item.mobile || ''}}</view>
							</view>
						</view>
					</view>
				</view>	
			</scroll-view> -->
		</view>
	</template>

<script>
	import * as Seller_API from '../../../api/member/seller.js'
	export default {
		data() {
			return {
				PartnersList:[],
				Stock:{},
				PartnersListLow:[], //未审核
				active:0,
				menuList:[
					{title : '已审核'},
					{title : '未审核'}
				]
			};
		},
		onShow() {
			this.GET_Stock()
			this.GET_PartnersList()
		},
		onPullDownRefresh() {
			setTimeout(()=> {
				uni.stopPullDownRefresh()
				this.GET_Stock()
				this.GET_PartnersList()
			}, 200);
		},
		methods:{
			GET_Stock(){
				Seller_API.getmyStock().then(res =>{
					this.Stock = res
				})
			},
			GET_PartnersList(index){
				if(index){
					this.active = index-1
				}
				if(this.active == 0){
					Seller_API.getPartnersList().then(res =>{
						this.PartnersList = res
					})
				}else{
					Seller_API.getPartnersListLow().then(res =>{
						this.PartnersList = res
					})
				}
			},
			GET_PartnersListLow(){
				this.active = 1
				
			},
			addPartner(){
				uni.navigateTo({
					url:'./addSeller'
				})
			},
			unixToDate(unix, format) {
			  let _format = format || 'yyyy-MM-dd hh:mm:ss'
			  const d = new Date(unix)
			  const o = {
			    'M+': d.getMonth() + 1,
			    'd+': d.getDate(),
			    'h+': d.getHours(),
			    'm+': d.getMinutes(),
			    's+': d.getSeconds(),
			    'q+': Math.floor((d.getMonth() + 3) / 3),
			    S: d.getMilliseconds()
			  }
			  if (/(y+)/.test(_format)) _format = _format.replace(RegExp.$1, (d.getFullYear() + '').substr(4 - RegExp.$1.length))
			  for (const k in o) if (new RegExp('(' + k + ')').test(_format)) _format = _format.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
			  return _format
			},
			goStock(){
				uni.navigateTo({
					url:'../common/addStock?type=partner&active='+this.active
				})
			}
		}
	}
</script>

<style lang="scss">

</style>
